package com.cloud.pole.shop.controller.goods;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.pole.common.constant.CommonConstants;
import com.cloud.pole.common.exception.BaseException;
import com.cloud.pole.common.exception.ParamException;
import com.cloud.pole.common.msg.ApiRestResponse;
import com.cloud.pole.common.util.RegexUtils;
import com.cloud.pole.common.util.TreeUtil;
import com.cloud.pole.shop.biz.goods.ShopGoodsCategoryBiz;
import com.cloud.pole.shop.controller.IndexController;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsCategory;
import com.cloud.pole.shop.model.vo.IndexVo;
import com.cloud.pole.shop.model.vo.goods.GoodsCategoryTree;
import com.cloud.pole.shop.model.vo.goods.GoodsDetailVo;
import com.cloud.pole.shop.model.vo.goods.ShopGoodsPromotionByTypeVo;
import com.cloud.pole.shop.model.vo.goods.ShopGoodsVo;
import com.cloud.pole.shop.service.IndexService;
import com.cloud.pole.shop.service.goods.GoodsCategoryService;
import com.cloud.pole.shop.service.goods.GoodsService;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example;

/*
*2019年2月21日
*cloud-shop
*author:frank-chen
*/
@Controller
@Slf4j
@RequestMapping("/goodsCategory/front")
public class GoodsCategoryController {
	@Autowired
	private GoodsCategoryService goodsCategoryService;

	@Autowired
	private ShopGoodsCategoryBiz shopGoodsCategoryBiz;
	
	@ResponseBody
	@RequestMapping("/getTreeList")
    public ApiRestResponse<List<GoodsCategoryTree>> getAllTreeList(){   	
    	try {
			return ApiRestResponse.success(CommonConstants.STATUS_OK_MESSAGE, goodsCategoryService.getAllTreeList());
    	} catch (BaseException e) {
			return ApiRestResponse.fail(e.getStatus(), e.getMessage(), null);
		} catch (Exception e) {
			log.error(CommonConstants.STATUS_ERROR_MESSAGE + "{}", e.getMessage(), e);
			return ApiRestResponse.fail(CommonConstants.STATUS_ERROR_MESSAGE, null);
		}
    }
	
	@ResponseBody
	@RequestMapping("/getTreeListByShopId")
    public ApiRestResponse<List<GoodsCategoryTree>> getTreeListByShopId(
    		@RequestParam(defaultValue = "1") String shopId){   	
		System.out.println(shopId);
    	try {
			ParamException.err(StringUtils.isBlank(shopId), "shopId不能为空");
			ParamException.err(!RegexUtils.isInteger(shopId), "shopId错误");
			return ApiRestResponse.success(CommonConstants.STATUS_OK_MESSAGE, goodsCategoryService.getTreeListByShopId(Integer.parseInt(shopId)));
    	} catch (BaseException e) {
			return ApiRestResponse.fail(e.getStatus(), e.getMessage(), null);
		} catch (Exception e) {
			log.error(CommonConstants.STATUS_ERROR_MESSAGE + "{}", e.getMessage(), e);
			return ApiRestResponse.fail(CommonConstants.STATUS_ERROR_MESSAGE, null);
		}
    }
}
